<template>
	<view>
		<view class="" v-if="isShow">
			<view class="header">
				<view class="big">
					<view class="left">
						<!-- #ifdef H5 -->
						<u--image width="80px" height="80px" :src="userinfo.avatarurl" shape="circle"></u--image>
						<!-- #endif -->
						<!-- #ifdef MP-WEIXIN -->
						<u--image width="80px" height="80px" :src=" 'http://localhost:3001'+userinfo.avatarurl "
							shape="circle">
						</u--image>
						<!-- #endif -->
						<view class="box">
							<view class="phone">
								{{userinfo.nickname}}
							</view>
							<view class="miss">
								完善资料让小U更懂你
							</view>
						</view>
					</view>
					<view class="day">
						<u-tag text="每日签到" type="error" icon="tags-fill" size="mini" plain plainFill></u-tag>
					</view>
				</view>
				<view class="box1">
					<view>
						<text>12</text>
						<text>我的收藏</text>
					</view>
					<view>
						<text>12</text>
						<text>浏览记录</text>
					</view>
					<view>
						<text>￥0</text>
						<text>我的红包</text>
					</view>
					<view>
						<text>12</text>
						<text>优惠券</text>
					</view>
				</view>
				<view class="ding">
					<view class="top">
						<text class="text1">我的订单</text>
						<text class="text2">全部订单 ></text>
					</view>
					<view class="bottom">
						<view>
							<image src="../../static/Image/m-index/me1.png" mode=""></image>
							<text>代付款</text>
						</view>
						<view>
							<image src="../../static/Image/m-index/me2.png" mode=""></image>
							<text>代发货</text>
						</view>
						<view>
							<image src="../../static/Image/m-index/me3.png" mode=""></image>
							<text>代确认</text>
						</view>
						<view>
							<image src="../../static/Image/m-index/me4.png" mode=""></image>
							<text>售后/退款</text>
						</view>
					</view>
				</view>
			</view>

			<view class="content">
				<view>
					<view class="v">
						<u-icon name="map" color="#FF9900"></u-icon>
						<text>地址管理</text>
					</view>
					<text>></text>
				</view>
				<view>
					<view class="v">
						<u-icon name="red-packet" color="#FF9900"></u-icon>
						<text>我的钱包</text>
					</view>
					<text>剩余200U币 ></text>
				</view>
				<view>
					<view class="v">
						<u-icon name="scan" color="#FF9900"></u-icon>
						<text>我的二维码</text>
					</view>
					<text>></text>
				</view>
				<view>
					<view class="v">
						<u-icon name="account" color="#FF9900"></u-icon>
						<text>我的小伙伴</text>
					</view>
					<text>></text>
				</view>
				<view>
					<view class="v">
						<u-icon name="github-circle-fill" color="#FF9900"></u-icon>
						<text>0元试用</text>
					</view>
					<text>></text>
				</view>
			</view>
		</view>


		<view class="Box" v-else>
			<view class="login_title">
				<image src="../../static/Image/m-index/orange-logo.png" mode=""></image>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<button type="primary" open-type="getPhoneNumber" @getphonenumber="weixinLogin"
				hover-class="touchOpacity">微信用户一键登录</button>
			<!-- #endif -->
			<!-- #ifdef H5 -->
			<view class="login_text" @click="toLogin" hover-class="touchOpacity">
				手机号验证注册/登录
			</view>
			<!-- #endif -->
		</view>
	</view>
</template>

<script>
	import checkLogin from '../../common/checkLogin.js'
	import {
		wxLogin
	} from '../../request/app.js'
	export default {
		data() {
			return {
				isShow: '',
				userinfo: {}
			}
		},
		onShow() {
			let userinfo = uni.getStorageSync('userinfo')
			this.userinfo = userinfo
			checkLogin()
			this.isShow = checkLogin()
		},
		methods: {
			toLogin() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			weixinLogin(e) {
				console.log(e, 'eeee');
				const {
					iv,
					encryptedData
				} = e.detail
				if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
					uni.showToast({
						title: "拒绝后无法登录",
						icon: 'error'
					})
				} else {
					let _this = this
					wx.login({
						success(res) {
							console.log(res, '响应');
							wxLogin({
								code: res.code,
								iv,
								encryptedData
							}).then(res => {
								console.log(res, '一键登录结果');
								if (res.data.code == 200) {
									uni.setStorageSync('userinfo', res.data.list)
									checkLogin()
									let userinfo = wx.getStorageSync('userinfo')
									_this.userinfo = userinfo
									_this.isShow = checkLogin()
								}
							})
						}
					})
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #eee;
	}

	.header {
		background-color: #FF6633;
		height: 350rpx;
	}

	.header .big {
		display: flex;
		justify-content: space-between;
		color: #fff;
	}

	.header .big .left {
		display: flex;
		margin-left: 20rpx;
	}

	.header .big .left .box {
		margin-left: 20rpx
	}

	.header .big .left .box .miss {
		width: 240rpx;
		text-align: center;
		border: 1px solid #fff;
	}

	.header .box1 {
		display: flex;
		justify-content: space-around;
		color: #fff;
	}

	.header .box1 view {
		display: flex;
		flex-direction: column;
		text-align: center;
	}

	.header .ding {
		width: 700rpx;
		height: 200rpx;
		margin-left: 25rpx;
		background-color: #fff;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.header .ding .top {
		display: flex;
		justify-content: space-between;
	}

	.header .ding .top .text1 {
		font-weight: bold;
		padding-left: 20rpx;
	}

	.header .ding .top .text2 {
		padding-right: 20rpx;
		color: #FF6633;
	}

	.header .ding .bottom view {
		display: flex;
		flex-direction: column;
		align-items: center;

	}

	.header .ding .bottom image {
		width: 50rpx;
		height: 45rpx;
	}

	.header .ding .bottom {
		display: flex;
		justify-content: space-around;
	}

	.content {
		background-color: #fff;
		margin-top: 120rpx;
	}

	.content view {
		height: 75rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.content view .v {
		margin-left: 20rpx;
	}

	.content view text {
		margin-right: 20rpx;
	}

	.Box {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.login_title {
		margin-top: 500rpx;
	}

	.login_title image {
		width: 600rpx;
		height: 120rpx;
	}

	.login_logo {
		width: 364rpx;
		height: 98rpx;
	}

	.login_but {
		margin: 64rpx 0 40rpx 0;
		width: 670rpx;
		line-height: 98rpx;
		text-align: center;
		background-color: #FF6040;
		font-size: 32rpx;
		color: #FFFFFF;
	}

	.login_text {
		font-size: 35rpx;
		color: #339933;
	}
</style>
